package org.example.sunrise.models;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.sunrise.core.Cache;
import org.example.sunrise.core.SpriteEnum;
import org.example.sunrise.domains.SpriteInfo;

import java.io.IOException;

public class LocalSpriteModel extends Cache<SpriteEnum, SpriteInfo> {
    private final ObjectMapper mapper = new ObjectMapper();

    @Override
    public SpriteInfo apply(SpriteEnum s) {
        try {
            return mapper.readValue(LocalSpriteModel.class.getResource(s.getName() + ".json"), SpriteInfo.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
